const express=require("express");
const { count } = require("node:console");
var router=express.Router();
var pool=require("../pool");
router.get("/page",(req,res)=>{
	var pno=req.query.pno;
	var lid=req.query.lid;
	let start=(pno-1)*60;
  var sql="SELECT * FROM mx_book where lid=? limit ?,60";
  pool.query(sql,[lid,start],(err,result)=>{
    if(err){
      console.log(err);
    }
    res.send(result);
	console.log(result);
  })
})

router.get("/count",(req,res)=>{
  var lid=req.query.lid;
  var sql="SELECT * FROM mx_book where lid=?";
  pool.query(sql,[lid],(err,result)=>{
    if(err){
      console.log(err);
    }
    res.send(result);
	console.log(result);
  })
})
router.get("/fid",(req,res)=>{
  var sql="select * from mx_channel_family";
   pool.query(sql,(err,result)=>{
  	  if(err){
  		  console.log(err);
  	  }
  	  res.send(result);
  	  console.log(result);
   })
})
router.get("/:fid",(req,res)=>{
	let fid=req.params.fid;
	var sql="select * from mx_family where fid=?";
	pool.query(sql,[fid],(err,result)=>{
		if(err){
			console.log(err);
		}
		res.send(result);
		console.log(result);
	})
})
// router.get('/:pno',(req,res)=>{
// 	let obj=req.query;
// 	let pno=obj.pno;
// 	//计算开始查询的值
// 	let start=(obj.pno-1)*60;
// 	//执行SQL命令
// 	pool.query('select * from mx_book limit ?,?',[start,60],(err,result)=>{
// 	if (err){
// 		next(err);
// 		return;
// 	}
// 	console.log(result);
// 	res.send({code:200,msg:'查询成功',data:result})
// 	})
// })
module.exports=router;
//http://localhost:3000/index
 